package com.wechat.back.mapper;

import com.wechat.back.pojo.articles.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {
    //新增审核通过文章
    @Insert("insert into article_allow(title,content,cover_img,state,inspect_state,category_id,create_user,create_time,update_time) " +
            "values(#{title},#{content},#{coverImg},#{state},#{inspectState},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void add(Article article);

    //新增待审核文章
    @Insert("insert into article_inspect(title,content,cover_img,state,inspect_state,category_id,create_user,create_time,update_time) " +
            "values(#{title},#{content},#{coverImg},#{state},#{inspectState},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void addToInspect(Article article);

    //新增驳回文章
    @Insert("insert into article_disallow(title,content,cover_img,state,inspect_state,disallow_desc,category_id,create_user,create_time,update_time) " +
            "values(#{title},#{content},#{coverImg},#{state},#{inspectState},#{disallowDesc},#{categoryId},#{createUser},#{createTime},#{updateTime})")
    void addToDisAllow(Article article);


    //查询已通过文章
    List<Article> list(Integer userId, Integer categoryId, String state, Integer id);

    //查询驳回文章
    List<Article> listDisallow(Integer userId, Integer categoryId, String state, Integer id);

    //查询已通过的所有文章
    List<Article> listAll(Integer categoryId, String state);

    //查询待审核的所有文章
    List<Article> listAllToInspect(Integer categoryId, String state);

    //查询驳回所有的文章
    List<Article> listAllToDisAllow(Integer categoryId, String state);

    //删除已通过文章
    @Delete("delete from article_allow where id=#{id}")
    void deleteById(Integer id);

    //删除待审核文章
    @Delete("delete from article_inspect where id=#{id}")
    void deleteToInspectById(Integer id);

    //删除驳回文章
    @Delete("delete from article_disallow where id=#{id}")
    void deleteToDisAllowById(Integer id);


    //修改已通过文章
    @Update("update article_allow set title=#{title},content=#{content},cover_img=#{coverImg},state=#{state},inspect_state=#{inspectState}," +
            "category_id=#{categoryId},update_time=#{updateTime} where id=#{id}")
    void update(Article article);

    //修改待审核文章
    @Update("update article_inspect set title=#{title},content=#{content},cover_img=#{coverImg},state=#{state},inspect_state=#{inspectState}," +
            "category_id=#{categoryId},update_time=#{updateTime} where id=#{id}")
    void updateToInspect(Article article);

    //修改驳回文章
    @Update("update article_disallow set title=#{title},content=#{content},cover_img=#{coverImg},state=#{state},inspect_state=#{inspectState},disallow_desc=#{disallowDesc}," +
            "category_id=#{categoryId},update_time=#{updateTime} where id=#{id}")
    void updateToDisAllow(Article article);

    //查询已通过文章
    @Select("select * from article_allow where id=#{id}")
    Article findById(Integer id);

    //查询待审核文章
    @Select("select * from article_inspect where id=#{id}")
    Article findToInspectById(Integer id);

    //查询驳回文章
    @Select("select * from article_disallow where id=#{id}")
    Article findToDisAllowById(Integer id);
}
